package tr.com.netgis;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import tr.com.netgis.log.LogArrayAdapter;
import tr.com.netgis.pojo.NGLocation;
import tr.com.netgis.util.Utility;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.ListView;

import com.google.android.maps.OverlayItem;


/**
 * 
 * @author NetGis
 *
 */
public class NotPostedLocationListActivity extends NGListActivity {

	/*
	private Button btnTemizle;
	private Button btnGonderilmeyenKacTane;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.notpostedlist);
		btnTemizle = (Button) findViewById(R.id.ng_notposted_btnListTemizle);
		btnGonderilmeyenKacTane = (Button) findViewById(R.id.ng_notposted_btnGonderilmeyenler);
		
		btnTemizle.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				mHelper.deleteAllLocations();
				mCursor.requery();
				mAdapter.notifyDataSetChanged();
			}
		});
		final Context ctx = this;
		btnGonderilmeyenKacTane.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Toast toast = Toast.makeText(ctx, Long.toString( mHelper.howManyLocations()), 3000);
				toast.show();	
			}	
		});
	}
	
	@Override
    public void onResume() {
        super.onResume();
        String[] columns = NGDbHelper.getColumns(Table.LOCATIONS);
        mCursor = mDb.query(NGDbHelper.TABLE_NAME_LOCATIONS, columns, null, null, null, null, null, null);
        String[] headers = new String[] {NGDbHelper.COL_LAT, NGDbHelper.COL_LON};
        mAdapter = new SimpleCursorAdapter(this, android.R.layout.two_line_list_item,
                mCursor, headers, new int[]{android.R.id.text1, android.R.id.text2});
        //getListView().setAdapter(mAdapter); //TODO
    }
	*/
	
	private ListView logList;
	//private TextView logView;
	//private Button btnLogViewClear;

	private List<NGLocation> listItems = new ArrayList<NGLocation>();
	private LogArrayAdapter adapter;
	final SimpleDateFormat SDF = Utility.createSimpleDateFormat();
	public static String provider;
	static OverlayItem _overItem;


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.notpostedlist);
		
		logList = (ListView) findViewById(R.id.notPostedList);
		listItems = mHelper.listUnsentLocations();
		adapter = new LogArrayAdapter(this, listItems);
		logList.setAdapter(adapter);
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
	    MenuInflater inflater = this.getMenuInflater();
	    inflater.inflate(R.menu.menu_refresh_delete, menu);
		super.onCreateOptionsMenu(menu);
	    return true;
	}
	
	private void trash(){
		mHelper.deleteLocations(NGLocation.UNSENT);
		listItems.removeAll(listItems);
		adapter.notifyDataSetChanged();
	}
	
	private void refresh(){
		//TODO 
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
	    // Handle item selection
	    switch (item.getItemId()) {
	    case R.id.menu_refresh:
	        refresh();
	        return true;
	    case R.id.menu_trash:
	        trash();
	        return true;
	   
	    default:
	        return super.onOptionsItemSelected(item);
	    }
	}

	@Override
	protected void onResume() {
		super.onResume();
	}	
	 
}
